package com.huahua.api.entity.vo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 表格对比结果VO
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TableComparisonResultVo {

    /**
     * 对比ID（用于下载结果）
     */
    private String comparisonId;

    /**
     * 对比时间
     */
    private LocalDateTime comparisonTime;

    /**
     * 源文件信息
     */
    private FileInfo sourceFile;

    /**
     * 目标文件信息
     */
    private FileInfo targetFile;

    /**
     * 对比摘要
     */
    private ComparisonSummary summary;

    /**
     * 结构差异
     */
    private StructureDiff structureDiff;

    /**
     * 数据差异详情
     */
    private List<RowDiff> rowDiffs;

    /**
     * 文件信息
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class FileInfo {
        private String fileName;
        private String format;
        private Integer rowCount;
        private Integer columnCount;
        private List<String> columns;
    }

    /**
     * 对比摘要
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class ComparisonSummary {
        private Integer totalRows;
        private Integer matchedRows;
        private Integer addedRows;
        private Integer deletedRows;
        private Integer modifiedRows;
        private Double matchRate;
    }

    /**
     * 结构差异
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class StructureDiff {
        private List<String> addedColumns;
        private List<String> deletedColumns;
        private List<String> commonColumns;
        private Map<String, String> renamedColumns;
    }

    /**
     * 行差异
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class RowDiff {
        private String diffType; // ADDED, DELETED, MODIFIED
        private Integer sourceRowIndex;
        private Integer targetRowIndex;
        private Map<String, Object> keyValues;
        private List<CellDiff> cellDiffs;
    }

    /**
     * 单元格差异
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class CellDiff {
        private String columnName;
        private Object sourceValue;
        private Object targetValue;
        private String diffType; // VALUE_CHANGED, TYPE_CHANGED
    }
}
